﻿<!DOCTYPE html>
<html lang="en">
<head>
    <title id="Description">Column Formatting in jqxTreeGrid.</title>
    <meta name="description" content="Column Formatting - JavaScript Tree Grid Demo | jQWidgets"> 
    <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="../../scripts/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdatatable.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxtreegrid.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script>
    <script type="text/javascript" src="../sampledata/generatedata.js"></script>
    <script type="text/javascript" src="../../scripts/demos.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var source =
         {
             dataType: "array",
             dataFields: [
                 { name: "name", type: "string" },
                 { name: "quantity", type: "number" },
                 { name: "id", type: "number" },
                 { name: "parentid", type: "number" },
                 { name: "price", type: "number" },
                 { name: "date", type: "date" },
                 { name: "customer", type: "string" }
             ],
             hierarchy:
             {
                 keyDataField: { name: 'id' },
                 parentDataField: { name: 'parentid' }
             },
             id: 'id',
             localData: generateordersdata()
         };
            var dataAdapter = new $.jqx.dataAdapter(source);
            // create Tree Grid
            $("#treeGrid").jqxTreeGrid(
            {
                width: 850,
                height: 350,
                source: dataAdapter,
                sortable: true,
                ready: function () {
                    $("#treeGrid").jqxTreeGrid('expandRow', '2');
                },
                columns: [
                  { text: 'Order Name', dataField: "name", align: 'center', width: 200 },
                  { text: 'Customer', dataField: "customer", align: 'center', width: 200 },
                  { text: 'Price', dataField: "price", cellsFormat: "c2", align: 'center', cellsAlign: 'right', width: 100 },
                  {
                      text: 'Order Date', dataField: "date", align: 'right', cellsFormat: "d", cellsAlign: 'right'
                  }
                ]
            });

            $("#dateFormats").jqxDropDownList({ selectedIndex: 0, autoDropDownHeight: true, source: ['Short Date', 'Long Date', 'Long date, Short Time', 'Long date, Long Time', 'Month/Year', 'Month/Day', 'Custom'], height: 25 });
            $("#dateFormats").on('change', function (event) {
                var index = event.args.index;
                switch (index) {
                    case 0:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'date', 'cellsFormat', 'd');
                        break;
                    case 1:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'date', 'cellsFormat', 'D');
                        break;
                    case 2:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'date', 'cellsFormat', 'f');
                        break;
                    case 3:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'date', 'cellsFormat', 'F');
                        break;
                    case 4:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'date', 'cellsFormat', 'Y');
                        break;
                    case 5:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'date', 'cellsFormat', 'M');
                        break;
                    case 6:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'date', 'cellsFormat', 'yyyy-MM-dd HH:mm:ss');
                        break;
                }
            });
            $("#numberFormats").jqxDropDownList({ selectedIndex: 5, autoDropDownHeight: true, source: ['n', 'f1', 'f2', 'f3', 'c1', 'c2', 'c3', 'p', 'p2', 'p3'], height: 25 });
            $("#numberFormats").on('change', function (event) {
                var index = event.args.index;
                switch (index) {
                    case 0:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'price', 'cellsFormat', 'n');
                        break;
                    case 1:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'price', 'cellsFormat', 'f1');
                        break;
                    case 2:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'price', 'cellsFormat', 'f2');
                        break;
                    case 3:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'price', 'cellsFormat', 'f3');
                        break;
                    case 4:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'price', 'cellsFormat', 'c1');
                        break;
                    case 5:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'price', 'cellsFormat', 'c2');
                        break;
                    case 6:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'price', 'cellsFormat', 'c3');
                        break;
                    case 7:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'price', 'cellsFormat', 'p');
                        break;
                    case 8:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'price', 'cellsFormat', 'p2');
                        break;
                    case 9:
                        $("#treeGrid").jqxTreeGrid('setColumnProperty', 'price', 'cellsFormat', 'p3');
                        break;
                }
            });
        });
    </script>
</head>
<body class='default'>
    <div id="treeGrid">
    </div>
    <div style="font-size: 13px; font-family: Verdana; width: 600px; margin-top: 10px;">
        <div style="float: left; width: 300px;">
            <h4>Shipped Date</h4>
            <div id="dateFormats"></div>
        </div>
        <div style="float: left; width: 300px;">
            <h4>Price</h4>
            <div id="numberFormats"></div>
        </div>
    </div>
</body>
</html>
